package com.infore.siteManagement.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.infore.siteManagement.service.IFileService;
import com.infore.siteManagement.util.ResultEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(value = "文件管理接口", tags = { "文件管理接口" })
@RestController
@RequestMapping("/file")
public class FileController {

	@Autowired
	private IFileService iFileService;

	@ApiOperation(value = "文件下载", notes = "文件下载")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "fileId", value = "文件id", paramType = "query", required = true, dataType = "String") })
	@GetMapping(value = "/dowloadFile")
	public ResultEntity dowloadFile(HttpServletResponse response, String fileId) {
		return iFileService.dowloadFile(response, fileId);
	}

	@ApiOperation(value = "文件删除", notes = "文件删除")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "fileId", value = "文件id,可删除多个", paramType = "query", required = true, dataType = "String") })
	@DeleteMapping(value = "/delete")
	public ResultEntity delete(String fileId) {
		return iFileService.delete(fileId);
	}

	public ResultEntity uploadSingle(String path, MultipartFile[] multipartFiles) {
		return iFileService.uploadSingle(path, multipartFiles);
	}
}
